package com.sky.controller.admin;

import com.sky.dto.AddSetMealDTO;
import com.sky.dto.QuerySetmealByPageDTo;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.PageVo;
import com.sky.vo.SetmealVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关操作")
public class SetMealController {

    @Autowired
    private SetmealService service;

    @PostMapping
    @ApiOperation("新增套餐接口")
    @CacheEvict(cacheNames = "setmealCache",key = "#addSetMealDTO.categoryId")
    public Result<String> add(@RequestBody AddSetMealDTO addSetMealDTO){
        service.add(addSetMealDTO);
        return Result.success();
    }
    @PutMapping
    @ApiOperation("修改套餐接口")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<String> update(@RequestBody AddSetMealDTO addSetMealDTO){
        service.update(addSetMealDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售停售接口")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<String> setStatus(@PathVariable Integer status,Long id){
        service.setStatus(status,id);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页查询套餐接口")
    public Result<PageVo<SetmealVo>> page(QuerySetmealByPageDTo querySetmealByPageDTo){
        PageVo<SetmealVo> pageVo=service.queryByPage(querySetmealByPageDTo);
        return Result.success(pageVo);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据套餐id查询套餐接口")
    public Result<SetmealVo> queryById(@PathVariable Long id){
        SetmealVo setmealVo=service.queryById(id);
        return Result.success(setmealVo);
    }
    @DeleteMapping
    @ApiOperation("删除套餐接口")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<String> delete(@RequestParam List<Long> ids){
        service.delete(ids);
        return Result.success();
    }

}
